home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Libraries / VideoToolbox 95.04.18 / Notes / rgb to luminance.note < prev    next >
Text File  |  1993-12-15  |  4KB  |  15 lines

  1. "rgb to luminance.note"
  2. HISTORY:
  3. 12/9/92 dgp wrote it.
  4. 3/5/93 dgp edited
  5. 4/26/93 dgp edited
  6.  
  7. How luminance depends on the rgb numbers. (For Gil Fuchs, who asked.)
  8.  
  9. The rgb triplet is sent to the video card's CLUT (color lookup table) by issuing a setEntries control call to the video driver. (That's the low-level mechanism, which normally would be invoked by the Palette or Color Manager, but which for vision experiments is useful to do yourself, by calling GDSetEntries, or it's alias LoadLuminances.) Let's assume for the moment that you've set the screen (i.e. the video driver) to "color" mode. The driver transforms each of the three numbers by a gamma-correction table. I use GDUncorrectedGamma() to make the gamma table an identity transform. Then the transformed triplet is put into one of the 256 entries of the CLUT. If you've set the screen (i.e. the video driver) to "monochrome" mode, instead of "color", then the driver computes a weighted average of the three rgb values, .3*red + .59*green + .11*blue, to produce a single "luminance" number that is then passed through the gamma table and loaded into all three parts of the clut entry. (The formula given above varies slightly among video cards of different manufacturers. TimeVideo measures and reports the formula actually used by your video driver.)
  10.  
  11. During each video frame the video card retrieves each pixel, one by one, from its video memory and passes it to the clut. Apple defines two different general modes of operation of the clut: "clut" mode, which supports pixel-depths of 1, 2, 4, and 8 bits and "direct" mode, which supports pixel depths of 16 and 32 bits. (A third mode is called "fixed" and is equivalent to the "clut" mode, except that the clut's contents cannot be changed.) In "clut" mode the pixel is treated as one number that is used as an index into the clut. When a pixel arrives at the clut, it's value is used as an index to select one of the clut entries, an rgb color, a triplet. In "direct" mode the pixel is broken up into three numbers, either three 5-bit numbers, out of a 16-bit pixel, or three 8-bit numbers, out of a 32-bit pixel. (The other bits are ignored.) These three numbers are used as separate indexs into the clut, each yielding a single number. Normally the clut is linear, except for gamma correction, when in direct mode, but you can load anything you want. Finally, whether in "clut" or "direct" mode, the resulting triplet is fed to three digital to analog converters that each produce a voltage linearly related to its number. Roughly, 0 produces zero volts and 255 produces 1 volt. These voltages go to the monitor. If the monitor is monochrome, the red and blue voltages are not connected to anything, and the green voltage controls the luminance, which is approximately the square of the voltage. If it's a color monitor then each voltage controls a separate gun, which all have essentially the same nonlinear relationship to voltage, except for a luminance scale factor. 
  12.  
  13. If you have an ISR video attenuator, then the three voltages are summed, with unequal weighting, to produce a single voltage that is used to drive a monochrome monitor. So it's important that you set the screen to "color" if you're using an ISR video attentuator.
  14.  
  15. You can also bypass the video driver, using SetEntriesQuickly, to load the CLUT directly. SetEntriesQuickly ignores the video driver's gamma table and color/monochrome state, always loading the triplet directly into the appropriate CLUT entry, with no transformation.